package com.luck.service;


import com.luck.api.UserManager;
import com.luck.dao.UsersMapper;
import com.luck.model.po.Users;
import com.luck.common.UserConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Hua wb on 2018/3/14.
 */
@Service
public class UserService implements UserManager {
    @Autowired
    private UsersMapper usersMapper;
    @Override
    public int insert(Users users) {
        return usersMapper.insertSelective(users);
    }

    @Override
    public int updateUsersToken(Users users) {
        return usersMapper.updateUsersToken(users.getUserId(), users.getToken());
    }

    @Override
    public int updateActivate(String token) {
        return usersMapper.updateActivate(UserConstant.USER_STATUS_ACTIVATE, token);
    }

    @Override
    public int deleteNoActivate() {
        return usersMapper.updateNoActivate(UserConstant.USER_STATUS_FROZEN, UserConstant.USER_STATUS_FROZEN);
    }

    @Override
    public Users getUsers(int id) {
        return usersMapper.selectByPrimaryKey(id);
    }

    @Override
    public int delUser(int id) {
        return usersMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Users> getUserList(Users users) {
        return usersMapper.getUsers(users);
    }

    @Override
    public Users checkUser(String email, String pwd) {
        return usersMapper.checkUser(email, pwd, UserConstant.USER_STATUS_ACTIVATE);
    }
}
